package com.xiaoKe.zhonghzu.global.dialog;

import android.os.Handler;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;

import com.xiaoKe.zhonghzu.R;
import com.xiaoKe.zhonghzu.databinding.DialogToastBinding;

public class ToastDialog extends CenterDialog<DialogToastBinding> {
    String str = "";
    Animation hyperspaceJumpAnimation;

    @Override
    protected void initView() {
        if (getTag().equals("1")) {//等待结束才能关闭
            hyperspaceJumpAnimation = AnimationUtils.loadAnimation(getContext(), R.anim.anim);
            // 使用ImageView显示动画
            hyperspaceJumpAnimation.setRepeatMode(10);
            binding.ivLoading.startAnimation(hyperspaceJumpAnimation);
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    dismiss();
                }
            }, 30000);

        } else if (str.equals("")) {
            hyperspaceJumpAnimation = AnimationUtils.loadAnimation(getContext(), R.anim.anim);
            // 使用ImageView显示动画
            hyperspaceJumpAnimation.setRepeatMode(10);
            binding.ivLoading.startAnimation(hyperspaceJumpAnimation);
        } else {
            binding.title.setVisibility(View.VISIBLE);
            binding.title.setText(getTag());
        }
    }

    @Override
    protected void initData() {

    }

    /**
     * @param content
     */
    public void setType(String content) {
        str = content;
        binding.ivLoading.setVisibility(View.GONE);
        binding.title.setVisibility(View.GONE);
        binding.ImgType.setImageResource(R.drawable.icon_succeed);
        binding.ImgType.setVisibility(View.VISIBLE);
        binding.lod.setText(content);
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                dismiss();
            }
        }, 500);
    }

    public void setIndext(String content) {
        if (null != binding.title) {
            binding.title.setVisibility(View.VISIBLE);
            binding.title.setText(content);
        }
    }
}
